package com.aaa.controller;

import com.aaa.service.S_NoticeService;
import com.aaa.util.EmpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/notice/")
public class S_NoticeController {
    @Autowired
    private S_NoticeService service;

    /**
     * @return controller指定跳转到html界面
     */
    @RequestMapping("notice")
    public String notic(){
        return "publicity/notice";
    }

    /**
     * @param map 查询公告
     * @return
     */
    @RequestMapping("selNotice" )
    @ResponseBody
    public Object selNotic(@RequestBody(required = false) Map map) {
        List<Map> data =service.selectNotice(map);
        Integer total=service.getCount(map);
        String name= EmpUtil.getEmp().getUsername();
        Map zmap=new HashMap();
        zmap.put("data",data);
        zmap.put("total",total);
        zmap.put("name",name);
        return  zmap;
    }


    /**
     * @param map 添加公告
     * @return
     */
    @RequestMapping("add")
    @ResponseBody
    public  Integer add(@RequestBody Map map){
        Integer row =service.addNotice(map);
        return row;
    }

    /**
     * @param map 修改公告方法
     * @return
     */
    @RequestMapping("update")
    @ResponseBody
    public Integer update(@RequestBody Map map){
        int row =service.updateNotice(map);
        System.out.println(map);
        return row;
    }

    /**
     * @param id 删除公告方法
     * @return
     */
    @RequestMapping("del/{id}")
    @ResponseBody
    public Integer del(@PathVariable Integer id){
        int row =service.delNotice(id);
        return row;
    }

}
